var id = getvl("id");
var goodsType = getvl("goodsType");
var packRate = getvl("packRate");
var zbDirectSeedingId = getvl("zbDirectSeedingId");

var type = getvl("type"); //首页焦点图
var userId = sessionStorage.getItem("userId");

var breadcrumbType = getvl("breadcrumbType");
if(breadcrumbType != "") {
	if(breadcrumbType == 1) {
		$('#breadcrumbType1').show();
		$('#breadcrumbType2').hide();
		$('#breadcrumbType3').hide();
		$('#breadcrumbType4').hide();
		$('#breadcrumbType5').hide();
	} else if(breadcrumbType == 2) {
		$('#breadcrumbType1').hide();
		$('#breadcrumbType2').show();
		$('#breadcrumbType3').hide();
		$('#breadcrumbType4').hide();
		$('#breadcrumbType5').hide();
	} else if(breadcrumbType == 3) {
		$('#breadcrumbType1').hide();
		$('#breadcrumbType2').hide();
		$('#breadcrumbType3').show();
		$('#breadcrumbType4').hide();
		$('#breadcrumbType5').hide();
	} else if(breadcrumbType == 4) {
		$('#breadcrumbType1').hide();
		$('#breadcrumbType2').hide();
		$('#breadcrumbType3').hide();
		$('#breadcrumbType4').show();
		$('#breadcrumbType5').hide();
	} else if(breadcrumbType == 5) {
		$('#breadcrumbType1').hide();
		$('#breadcrumbType2').hide();
		$('#breadcrumbType3').hide();
		$('#breadcrumbType4').hide();
		$('#breadcrumbType5').show();
	}
} else {
	$('#breadcrumbType1').show();
	$('#breadcrumbType2').hide();
	$('#breadcrumbType3').hide();
	$('#breadcrumbType4').hide();
	$('#breadcrumbType5').hide();
}

//店铺详情
if(userId != null) {

	goodsDetailById(id, userId, type);
} else {

	goodsDetailById(id, '', type);
}

//商品详情
//goodsDetailById(id);
//计算评论数量
getCommentCount(id);

//加载评论信息
loadMyEssayByComment(id, '', '');

function goodsDetailById(id, userId, type) {
	$("#serviceLevel").html(""); //服务等级
	$("#qualityLevel").html(""); //质量等级
	$("#carLevel").html(""); //物流等级

	$("#photoDetail").html(""); //放大镜
	$("#goodsStockList").html(""); //库存
	$("#shopInfo").html(""); //商家信息
	$("#shangxingoodsList").html(""); //上新商品
	$("#remaigoodsList").html(""); //热卖商品   
	$("#propertyLists").html(""); //属性

	$.ajax({
		url: urlcore + "/api/goods/selectOne1?id=" + id + "&userId=" + userId + "&type=" + type,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				var da = data.data;
				//面包屑导航
				$(".breadcrumbName").text(da.goodsTitle);
				//服务等级
				var serviceLevelName = '';
				if(da.shop.serviceLevel == 1) {
					serviceLevelName = '<img src="images/star_select.png" />';
				} else if(da.shop.serviceLevel == 2) {
					serviceLevelName = '<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />';
				} else if(da.shop.serviceLevel == 3) {
					serviceLevelName = '<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />';
				} else if(da.shop.serviceLevel == 4) {
					serviceLevelName = '<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />';
				} else if(da.shop.serviceLevel == 5) {
					serviceLevelName = '<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />';
				}
				$("#serviceLevel").append(serviceLevelName);

				//质量等级
				var qualityLevelName = '';
				if(da.shop.qualityLevel == 1) {
					qualityLevelName = '<img src="images/star_select.png" />';
				} else if(da.shop.qualityLevel == 2) {
					qualityLevelName = '<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />';
				} else if(da.shop.qualityLevel == 3) {
					qualityLevelName = '<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />';
				} else if(da.shop.qualityLevel == 4) {
					qualityLevelName = '<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />';
				} else if(da.shop.qualityLevel == 5) {
					qualityLevelName = '<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />';
				}
				$("#qualityLevel").append(qualityLevelName);
				//质量等级
				var carLevelName = '';
				if(da.shop.carLevel == 1) {
					carLevelName = '<img src="images/star_select.png" />';
				} else if(da.shop.carLevel == 2) {
					carLevelName = '<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />';
				} else if(da.shop.carLevel == 3) {
					carLevelName = '<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />';
				} else if(da.shop.carLevel == 4) {
					carLevelName = '<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />';
				} else if(da.shop.carLevel == 5) {
					carLevelName = '<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />&nbsp;<img src="images/star_select.png" />';
				}
				$("#carLevel").append(carLevelName);

				var coverUrl = isHasImg(da.coverUrl);
				//放大镜
				var photos = '';
				if(da.goodsUrl != null) {
					var photoArr = da.goodsUrl.split("***");
					$.each(photoArr, function(i, val) {
						val = isHasImg(val);
						photos += '<li>' +
							'<a href="' + val + '"><img class="lunbotuImg2" src="' + val + '" alt="Image Name" /></a>' +
							'</li>';
					});
				}

				photos += '<li>' +
					'<a href="' + coverUrl + '"><img class="lunbotuImg2" src="' + coverUrl + '" alt="Image Name" /></a>' +
					'</li>';
				var photoList =
					'<div class="examples_bg">' +
					'<div class="examples_image">' +
					'<img class="lunbotuImg" src="' + coverUrl + '" alt="' + coverUrl + '" />' +
					'<div class="desc">' +
					'<a href="#" class="collapse"></a>' +
					'<div class="block"></div>' +
					'</div>' +
					'</div>' +
					'<div class="mune_thumb">' +
					'<ul>' + photos + '</ul>' +
					'</div>' +
					'</div>';

				$('#photoDetail').append(photoList);
				//Banner 轮播图样式
				$(document).ready(function() {
					//隐藏登录页
					$(".closeLogin").click(function() {
						$(".public_simi_bg1").fadeOut();
					});

					var myCollection = da.myCollection == null ? '' : da.myCollection.status;

					//关注店铺
					if(myCollection == 1) {
						$(".Shoucang-goods img").attr("src", "images/shoucang1.png");
					} else {
						$(".Shoucang-goods img").attr("src", "images/shoucang.png");
					}

					//收藏商品
					$(".Shoucang-goods").click(function() {

						if(userId == '') {
							//显示登录页
							$(".public_simi_bg1").fadeIn();
						} else {
							var id = da.myCollection == null ? '' : da.myCollection.id;

							var src = $(this).find("img").attr("src");
							if(src == 'images/shoucang.png') {

								if(id == '') {
									//取消关注
									swal({
											title: "确认收藏吗?",
											//text: "You will not be able to recover this imaginary file!",
											type: "warning",
											showCancelButton: true,
											cancelButtonText: '取消',
											confirmButtonColor: "#DD6B55",
											confirmButtonText: "确定",
											closeOnConfirm: false
										},
										function() {
											$.ajax({
												url: urlcore + '/api/myCollection/add',
												type: "post",
												contentType: "application/json;charset=utf-8",
												data: JSON.stringify({
													"goodsId": da.id,
													"status": 1
												}),
												dataType: "json",
												success: function(data) {
													if(data.success == true) {
														//layer.alert("收藏成功");
														//跳转列表页
														//window.location.href = "2.2.0goods_detail.html?id=" + da.id;
														swal("OK!", "收藏成功", "success");
														//跳转列表页
														window.location.href = "2.2.0goods_detail.html?id=" + da.id;
														$(".Shoucang-goods img").attr("src", "images/shoucang1.png");
													} else if(data.code == 'OVERTIME') {
														var thisUrl = window.location.href;
														if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
															top.window.location.href = "1.0.0denglu.html";
														}
													} else {
														sweetAlert(data.msg);
													}

												},
												error: function() {
													sweetAlert("error");
												}

											});

										});

									/*if(!layer.confirm("确认收藏吗?")) {
										return;
									}
									$.ajax({
										url: urlcore + '/api/myCollection/add',
										type: "post",
										contentType: "application/json;charset=utf-8",
										data: JSON.stringify({
											"goodsId": da.id,
											"status": 1
										}),
										dataType: "json",
										success: function(data) {
											if(data.success == true) {
												layer.alert("收藏成功");

												//跳转列表页
												window.location.href = "2.2.0goods_detail.html?id=" + da.id;
											} else if(data.code == 'OVERTIME') {
												var thisUrl = window.location.href;
												if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
													top.window.location.href = "1.0.0denglu.html";
												}
											} else {
												layer.alert(data.msg);
											}

										},
										error: function() {
											layer.alert("error");
										}

									});*/
								} else {
									//取消关注
									swal({
											title: "确认收藏吗?",
											//text: "You will not be able to recover this imaginary file!",
											type: "warning",
											showCancelButton: true,
											cancelButtonText: '取消',
											confirmButtonColor: "#DD6B55",
											confirmButtonText: "确定",
											closeOnConfirm: false
										},
										function() {
											$.ajax({
												url: urlcore + '/api/myCollection/update1',
												type: "post",
												contentType: "application/json;charset=utf-8",
												data: JSON.stringify({
													"id": id,
													"status": 1
												}),
												dataType: "json",
												success: function(data) {
													if(data.success == true) {
														//layer.alert("收藏成功");
														//跳转列表页
														//window.location.href = "2.2.0goods_detail.html?id=" + da.id;

														swal("OK!", "收藏成功", "success");
														//跳转列表页
														window.location.href = "2.2.0goods_detail.html?id=" + da.id;

														$(".Shoucang-goods img").attr("src", "images/shoucang1.png");
													} else if(data.code == 'OVERTIME') {
														var thisUrl = window.location.href;
														if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
															top.window.location.href = "1.0.0denglu.html";
														}
													} else {
														sweetAlert(data.msg);
													}

												},
												error: function() {
													sweetAlert("error");
												}

											});

										});

									/*if(!layer.confirm("确认收藏吗?")) {
										return;
									}
									$.ajax({
										url: urlcore + '/api/myCollection/update',
										type: "post",
										contentType: "application/json;charset=utf-8",
										data: JSON.stringify({
											"id": id,
											"status": 1
										}),
										dataType: "json",
										success: function(data) {
											if(data.success == true) {
												layer.alert("收藏成功");

												//跳转列表页
												window.location.href = "2.2.0goods_detail.html?id=" + da.id;
											} else if(data.code == 'OVERTIME') {
												var thisUrl = window.location.href;
												if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
													top.window.location.href = "1.0.0denglu.html";
												}
											} else {
												layer.alert(data.msg);
											}

										},
										error: function() {
											layer.alert("error");
										}

									});*/
								}

							} else {
								//关注
								swal({
										title: "您已收藏,确认取消收藏吗?",
										//text: "You will not be able to recover this imaginary file!",
										type: "warning",
										showCancelButton: true,
										cancelButtonText: '取消',
										confirmButtonColor: "#DD6B55",
										confirmButtonText: "确定",
										closeOnConfirm: false
									},
									function() {
										$.ajax({
											url: urlcore + '/api/myCollection/update1',
											type: "post",
											contentType: "application/json;charset=utf-8",
											data: JSON.stringify({
												"id": id,
												"status": 2
											}),
											dataType: "json",
											success: function(data) {
												if(data.success == true) {
													//layer.alert("取消成功");
													//跳转列表页
													//window.location.href = "2.2.0goods_detail.html?id=" + da.id;
													swal("OK!", "取消成功", "success"); //跳转列表页
													window.location.href = "2.2.0goods_detail.html?id=" + da.id;
													$(".Shoucang-goods img").attr("src", "images/shoucang.png");
												} else if(data.code == 'OVERTIME') {
													var thisUrl = window.location.href;
													if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
														top.window.location.href = "1.0.0denglu.html";
													}
												} else {
													sweetAlert(data.msg);
												}

											},
											error: function() {
												sweetAlert("error");
											}

										});

									});

								/*if(!layer.confirm("您已收藏,确认取消收藏吗?")) {
									return;
								}
								$.ajax({
									url: urlcore + '/api/myCollection/update',
									type: "post",
									contentType: "application/json;charset=utf-8",
									data: JSON.stringify({
										"id": id,
										"status": 2
									}),
									dataType: "json",
									success: function(data) {
										if(data.success == true) {
											layer.alert("取消成功");

											//跳转列表页
											window.location.href = "2.2.0goods_detail.html?id=" + da.id;
										} else if(data.code == 'OVERTIME') {
											var thisUrl = window.location.href;
											if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
												top.window.location.href = "1.0.0denglu.html";
											}
										} else {
											layer.alert(data.msg);
										}

									},
									error: function() {
										layer.alert("error");
									}

								});*/

								/*$(".Shoucang-goods img").attr("src", "images/shoucang.png");*/
							}
						}

					});

					//Show Banner
					$(".examples_image .desc").show(); //Show Banner
					$(".examples_image .block").animate({
						opacity: 0.85
					}, 1); //Set Opacity

					//Click and Hover events for thumbnail list
					$(".mune_thumb ul li:first").addClass('active');
					$(".mune_thumb ul li").hover(function() {
						//Set Variables
						var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
						var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
						var imgDesc = $(this).find('.block').html(); //Get HTML of block
						var imgDescHeight = $(".examples_image").find('.block').height(); //Calculate height of block	

						if($(this).is(".active")) { //If it's already active, then...
							return false; // Don't click through
						} else {
							//Animate			
							$(".examples_image .block").animate({
								opacity: 0,
								marginBottom: -imgDescHeight
							}, 250, function() {
								$(".examples_image .block").html(imgDesc).animate({
									opacity: 0.85,
									marginBottom: "0"
								}, 250);
								$(".examples_image img").attr({
									src: imgTitle,
									alt: imgAlt
								});
							});
						}

						$(".mune_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
						$(this).addClass('active'); //add class of 'active' on this list only
						return false;

					}).hover(function() {
						$(this).addClass('hover');
					}, function() {
						$(this).removeClass('hover');
					});

					//Toggle
					$("a.collapse").click(function() {
						$(".examples_image .block").slideToggle();
						$("a.collapse").toggleClass("show");
					});

				});
				var moneys = 0;
				var num1 = 0; //已购多少件
				//库存
				var stockList = '';
				$.each(da.goodsStockList, function(i, n) {
					//已添加到购物车商品总个数
					num1 += n.myStock == null ? 0 : n.myStock.saleNum;
					//已添加到购物车商品单价
					var packRate = n.goodsCar == null ? 0 : n.goodsCar.packRate;
					//已添加到购物车商品购买个数
					var saleNum = n.myStock == null ? 0 : n.myStock.saleNum;
					//已添加到购物车商品总金额
					moneys += packRate * saleNum;
					stockList +=
						'<tr>' +
						'<td>' + n.size.sizeName + '</td>' +
						'<td>' + n.colour.colourName + '</td>' +
						'<td>可售' + n.leftNum + '件</td>' +
						'<td>' +
						'<div class="lt-rt">' +
						'<input type="hidden" class="stockId"  value="' + n.id + '">' +
						'<input type="hidden" class="leftNum"  value="' + n.leftNum + '">' +
						'<input type="button" class="minus" value="-">' +
						'<input type="text" class="result" onkeyup="myFunction(this);" value="' + saleNum + '">' +
						'<input type="button" class="add" value="+">' +
						'</div>' +
						'</td>' +
						'</tr>';

				});
				//数量
				$(function() {
					if(num1 > 0 && moneys > 0) {
						$('.detailedList').show();
						var detailedList = '<p>' + num1 + '件&nbsp;&nbsp;' + fmoney(moneys, 2) + '</p>';
						$('.detailedList').html(detailedList);
					}

					$(".add").click(function() {
						var t = $(this).parent().find('input[class*=result]');
						t.val(parseInt(t.val()) + 1);

						var num = 0;
						$(this).parents('table[class*=stockList1]').find('input[class*=result]').each(function(i, val) {
							num += parseInt(val.value);
						});

						if(num > 0) {

							$('.detailedList').show();
							var detailedList = '';
							if(goodsType != 2 && goodsType != 3) {
								if(num > da.tradeNumber) {
									var packMoney = da.packPrice * num;
									detailedList = '<p>' + num + '件&nbsp;&nbsp;' + fmoney(packMoney, 2) + '</p>';
								} else {
									var tradeMoney = da.tradePrice * num;
									detailedList = '<p>' + num + ' 件&nbsp;&nbsp;' + fmoney(tradeMoney, 2) + '</p>';
								}
							} else {

								var packRateMoney = packRate * num;
								detailedList = '<p>' + num + ' 件&nbsp;&nbsp;' + fmoney(packRateMoney, 2) + '</p>';
							}

							//var detailedList='<p>'+num+'件&nbsp;&nbsp;'++'元</p>';
							$('.detailedList').html(detailedList);
						}

					})
					$(".minus").click(function() {
						var t = $(this).parent().find('input[class*=result]');
						t.val(parseInt(t.val()) - 1);
						if(parseInt(t.val()) < 0) {
							t.val(0);
						}

						var num = 0;
						$(this).parents('table[class*=stockList1]').find('input[class*=result]').each(function(i, val) {
							num += parseInt(val.value);
						});

						if(num > 0) {
							$('.detailedList').show();
							var detailedList = '';

							if(goodsType != 2 && goodsType != 3) {
								if(num > da.packNumber) {
									var packMoney = da.packPrice * num;
									detailedList = '<p>' + num + '件&nbsp;&nbsp;' + fmoney(packMoney, 2) + '</p>';
								} else {
									var tradeMoney = da.tradePrice * num;
									detailedList = '<p>' + num + ' 件&nbsp;&nbsp;' + fmoney(tradeMoney, 2) + '</p>';
								}
							} else {

								var packRateMoney = packRate * num;
								detailedList = '<p>' + num + ' 件&nbsp;&nbsp;' + fmoney(packRateMoney, 2) + '</p>';
							}

							//var detailedList='<p>'+num+'件&nbsp;&nbsp;'++'元</p>';
							$('.detailedList').html(detailedList);
						} else {
							$('.detailedList').hide();
						}
					})
				});

				var yugao_detail = '';
				var youhuiprice = '';
				if(goodsType == 3) {
					yugao_detail = '<div class="yugao_detail">' +
						'<span>距离开始</span>' +
						'<div class="fr">' +
						'<div class="colockbox1" id="demo02">' +
						'<span class="hour">-</span>' +
						'<span class="minute">-</span>' +
						'<span class="second">-</span>' +
						'</div>' +
						'</div>' +
						'</div>';

					//packRate=packRate;

					youhuiprice = '<dd>' +
						'<h2>批发价</h2>' +
						'<h3>&yen;' + packRate + '<span>' + da.tradeNumber + '-' + da.packNumber + '件</span></h3>' +
						'</dd>' +
						'<dd>' +
						/*'<h2>拿货价</h2>' +
						'<h3>&yen;' + da.getPrice + '<span>5-' + da.getNumber + '件</span></h3>' +*/
						'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
						'</dd>' +
						'<dd>' +
						'<h2>打包价</h2>' +
						'<h3>&yen;' + packRate + '<span>' + (da.packNumber) + '件以上</span></h3>' +
						'</dd>';

				} else if(goodsType == 2) {
					//packRate=packRate;

					youhuiprice = '<dd>' +
						'<h2>批发价</h2>' +
						'<h3>&yen;' + packRate + '<span>' + da.tradeNumber + '-' + da.packNumber + '件</span></h3>' +
						'</dd>' +
						'<dd>' +
						/*'<h2>拿货价</h2>' +
						'<h3>&yen;' + da.getPrice + '<span>5-' + da.getNumber + '件</span></h3>' +*/
						'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
						'</dd>' +
						'<dd>' +
						'<h2>打包价</h2>' +
						'<h3>&yen;' + packRate + '<span>' + da.packNumber + '件以上</span></h3>' +
						'</dd>';
				} else {
					//packRate=da.tradePrice;
					//packRate=da.packPrice;

					youhuiprice = '<dd>' +
						'<h2>批发价</h2>' +
						'<h3>&yen;' + da.tradePrice + '<span>' + da.tradeNumber + '-' + da.packNumber + '件</span></h3>' +
						'</dd>' +
						'<dd>' +
						/*'<h2>拿货价</h2>' +
						'<h3>&yen;' + da.getPrice + '<span>5-' + da.getNumber + '件</span></h3>' +*/
						'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
						'</dd>' +
						'<dd>' +
						'<h2>打包价</h2>' +
						'<h3>&yen;' + da.packPrice + '<span>' + da.packNumber + '件以上</span></h3>' +
						'</dd>';
				}

				//是否支持混批
				var isMix = da.shop == null ? 0 : da.shop.isMix;
				var isMixName = '';
				if(isMix == 0) {
					isMixName = '本店不支持混批';
				} else {
					isMixName = '全店满 ' + da.shop.mixNumber + '件可以混批采购 ';
				}
				var goldRateName = '';
				if(da.shop.openGold != null && da.shop.openGold == 1) {

					var goldexchange = da.shop.goldexchange == null ? 0 : da.shop.goldexchange;

					goldRateName = '<li class="clearfix" style="margin-bottom: 0;">' +
						'<span>商品服务：</span>' +
						'<div class="detail_mid_fuwu">' +
						'<em>可用金币抵扣' + da.goldRate + '%</em>' +
						'<em>每件最高可赠送金币' + goldexchange + '个</em>' +
						'<em>' + isMixName + '</em>' +
						'</div>' +
						'</li>';
				}

				//商品详情和库存	<!--倒计时-- >
				var goodsDetailList =
					'<h1>' + da.goodsTitle + '</h1>' +
					yugao_detail +
					'<dl class="clearfix">' +
					youhuiprice +
					'</dl>' +
					'<ul>' +
					'<li class="clearfix">' +
					'<span>混批设置：</span>' +
					'<div>' +
					'<h6>' + isMixName + '</h6>' +
					'</div>' +
					'</li>' +
					'<li class="clearfix">' +
					'<span>尺码颜色：</span>' +
					'<div>' +
					'<table class="stockList1">' +
					stockList +
					'</table>' +
					'<br/><div hidden="hidden" style="color:#FF682F;font-size:large;font-weight:bold;" class="detailedList"></div>' +
					'</div>' +
					'</li>' +
					goldRateName +
					'<li class="clearfix detail_mid_time">' +
					'<span>更新时间：<i>' + da.gmtDatetime + '</i></span>' +
					'<span>浏览次数：<i>' + da.lookTime + '</i></span>' +
					'<span>收藏量：<i>' + da.collectNum + '</i></span>' +
					'</li>' +
					'</ul>' +
					'<div class="detail_mid_but clearfix">' +
					'<a class="add1" href="javascript:void(0)">立即结算</a>' +
					'<a class="add2" href="javascript:void(0)">加入进货车</a>' +
					'</div>';
				//12.2.0shouhuodizhi.html 立即结算
				//12.0.0gouwuche.html 加入进货车
				$(function() {
					//立即结算
					$(".add1").click(function() {

						//var t = $('.add').parent().find('input[class*=result]');
						var arr = '[';
						var num = 0;
						//var packRate = 0; //优惠价
						//var goodsType=0;//商品类型
						$('input[class*=result]').each(function(i, val) {
							num += parseInt(val.value);
						});
						$('input[class*=result]').each(function(i, val) {
							//num += parseInt(val.value);
							var stockId = $(this).parent().find('input[class*=stockId]').val();
							if(val.value > 0) {

								if(goodsType != 3 && goodsType != 2) {
									goodsType = 1;
									if(num >= da.tradeNumber && num < da.packNumber) {
										packRate = da.tradePrice;
									} else if(num >= da.packNumber) {
										packRate = da.packPrice;
									} /*else {
										alert("起批件数不够！");
										return;
									}*/
								}

								if(i == 0) {
									arr += '{"id":' + stockId + ',"saleNum":' + val.value + ',"zbDirectSeedingId":"' + zbDirectSeedingId + '","packRate":' + packRate + ',"goodsType":' + goodsType + '}';
								} else {
									arr += ',{"id":' + stockId + ',"saleNum":' + val.value + ',"zbDirectSeedingId":"' + zbDirectSeedingId + '","packRate":' + packRate + ',"goodsType":' + goodsType + '}';
								}

							}
						});
						arr += ']';

						if(userId == '') {
							//显示登录页
							$(".public_simi_bg1").fadeIn();
						} else if(num <= da.tradeNumber) {
							//layer.alert("请您至少选购一件商品");
							swal({
								title: "立即结算",
								text: "起批件数不够！",
								timer: 2000
							});
							return;
						} else {
							swal({
									title: "是否立即结算?",
									//text: "You will not be able to recover this imaginary file!",
									type: "warning",
									showCancelButton: true,
									cancelButtonText: '取消',
									confirmButtonColor: "#DD6B55",
									confirmButtonText: "确定",
									closeOnConfirm: false
								},
								function() {
									$.ajax({
										url: urlcore + '/api/goodsCar/add1',
										type: "post",
										contentType: "application/json;charset=utf-8",
										data: JSON.stringify({
											"myStocks": arr
										}),
										dataType: "json",
										success: function(data) {
											if(data.success == true) {
												//var goodsids = '[{"goodsId":' + da.id + '}]';
												location.href = "12.2.0shouhuodizhi.html";

												sessionStorage.setItem('ids', da.id);
											} else if(data.code == 'OVERTIME') {
												var thisUrl = window.location.href;
												if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
													top.window.location.href = "1.0.0denglu.html";
												}
											} else {
												sweetAlert(data.msg);
											}
										},
										error: function() {
											sweetAlert("error");
										}
									});
									//swal("OK!", "Your imaginary file has been deleted.", "success");
								});

							/*if(!layer.confirm("是否立即结算？")) {
								return;
							}
							$.ajax({
								url: urlcore + '/api/goodsCar/add1',
								type: "post",
								contentType: "application/json;charset=utf-8",
								data: JSON.stringify({
									"myStocks": arr
								}),
								dataType: "json",
								success: function(data) {
									if(data.success == true) {
										//var goodsids = '[{"goodsId":' + da.id + '}]';
										location.href = "12.2.0shouhuodizhi.html";

										sessionStorage.setItem('ids', da.id);
									}
								},
								error: function() {
									layer.alert("error");
								}
							});
*/
						}
					});

					//加入进货车
					$(".add2").click(function() {

						//var t = $('.add').parent().find('input[class*=result]');
						var arr = '[';
						var num = 0;
						//var packRate = 0; //优惠价
						$('input[class*=result]').each(function(i, val) {
							num += parseInt(val.value);
						});
						$('input[class*=result]').each(function(i, val) {
							//num += parseInt(val.value);
							var stockId = $(this).parent().find('input[class*=stockId]').val();
							//if(val.value > 0) {
							if(goodsType != 3 && goodsType != 2) {
								goodsType = 1;
								if(num >= da.tradeNumber && num < da.packNumber) {
									packRate = da.tradePrice;
								} else if(num >= da.packNumber) {
									packRate = da.packPrice;
								}/* else {
									alert("起批件数不够！");
									return;
								}*/
							}
							if(i == 0) {
								arr += '{"id":' + stockId + ',"saleNum":' + val.value + ',"zbDirectSeedingId":"' + zbDirectSeedingId + '","packRate":' + packRate + ',"goodsType":' + goodsType + '}';
							} else {
								arr += ',{"id":' + stockId + ',"saleNum":' + val.value + ',"zbDirectSeedingId":"' + zbDirectSeedingId + '","packRate":' + packRate + ',"goodsType":' + goodsType + '}';
							}
						});
						arr += ']';
						if(userId == '') {
							//显示登录页
							$(".public_simi_bg1").fadeIn();
						} else if(num < da.tradeNumber) {
							//sweetAlert("请您至少选购一件商品");
							swal({
								title: "购物车",
								text: "起批件数不够！",
								timer: 2000
							});
							//swal("结算", "请您至少选购一件商品！",timer: 2000)
							return;
						} else {
							swal({
									title: "是否加入购物车?",
									type: "warning",
									showCancelButton: true,
									cancelButtonText: '取消',
									confirmButtonColor: "#DD6B55",
									confirmButtonText: "确定",
									closeOnConfirm: false
								},
								function() {
									$.ajax({
										url: urlcore + '/api/goodsCar/add1',
										type: "post",
										contentType: "application/json;charset=utf-8",
										data: JSON.stringify({
											"myStocks": arr
										}),
										dataType: "json",
										success: function(data) {
											if(data.success == true) {
												//layer.alert("加入成功,您请继续购物");
												swal("OK!", "加入成功,您请继续购物.", "success");
											} else if(data.code == 'OVERTIME') {
												var thisUrl = window.location.href;
												if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
													top.window.location.href = "1.0.0denglu.html";
												}
											} else {
												sweetAlert(data.msg);
											}
										},
										error: function() {
											layer.alert("error");
										}
									});

								});

							/*		if(!layer.confirm("是否加入购物车？")) {
										return;
									}

									$.ajax({
										url: urlcore + '/api/goodsCar/add1',
										type: "post",
										contentType: "application/json;charset=utf-8",
										data: JSON.stringify({
											"myStocks": arr
										}),
										dataType: "json",
										success: function(data) {
											if(data.success == true) {
												layer.alert("加入成功,您请继续购物");
											}
										},
										error: function() {
											layer.alert("error");
										}
									});*/

						}
					});

				});

				$('#goodsStockList').append(goodsDetailList);
				//店铺等级
				var storeLevelImg = '';
				var storeLevelName = '';
				if(da.shop.storeLevel == 1) {
					storeLevelName = '普通店铺';
					storeLevelImg = '<img src="images/grade_tong.png" />';
				} else if(da.shop.storeLevel == 2) {
					storeLevelName = '银牌店铺';
					storeLevelImg = '<img src="images/grade_yin.png" />';
				} else if(da.shop.storeLevel == 3) {
					storeLevelName = '金牌店铺';
					storeLevelImg = '<img src="images/grade_jin.png" />';
				}
				//信誉等级
				var creditLevelImg = '';
				if(da.shop.creditLevel == 1) {
					creditLevelImg = '<img src="images/aixiin.png" />';
				} else if(da.shop.creditLevel == 2) {
					creditLevelImg = '<img src="images/aixiin.png" /><img src="images/aixiin.png" />';
				} else if(da.shop.creditLevel == 3) {
					creditLevelImg = '<img src="images/aixiin.png" /><img src="images/aixiin.png" /><img src="images/aixiin.png" />';
				} else if(da.shop.creditLevel == 4) {
					creditLevelImg = '<img src="images/aixiin.png" /><img src="images/aixiin.png" /><img src="images/aixiin.png" /><img src="images/aixiin.png" />';
				} else if(da.shop.creditLevel == 5) {
					creditLevelImg = '<img src="images/aixiin.png" /><img src="images/aixiin.png" /><img src="images/aixiin.png" /><img src="images/aixiin.png" /><img src="images/aixiin.png" />';
				}

				var headImg = da.shop.headImg == null ? "" : da.shop.headImg;
				headImg = isHasImg(headImg); //图片处理

				var storeName = da.shop.storeName == null ? "" : da.shop.storeName;
				var monthNew = da.shop.monthNew == null ? 0 : da.shop.monthNew;
				var lookTime = da.shop.lookTime == null ? 0 : da.shop.lookTime;
				var shopInfo =
					'<dl>' +
					'					<dt>' +
					'				<a href="10.1.0dianpu_detail.html?id=' + da.shop.id + '"><img src="' + headImg + '" /></a>' +
					'			</dt>' +
					'					<dd>' +
					'						<a href="10.1.0dianpu_detail.html?id=' + da.shop.id + '"><h6>' + storeName + '</h6></a>' +
					'						<p>' + da.shop.province + '-' + da.shop.city + '-' + da.shop.address + '</p>' +
					'					</dd>' +
					'				</dl>' +
					'				' +
					'				' +
					'				<ul>' +
					'					<li>' +
					'						店铺等级：' + storeLevelImg +
					'						<em>' + storeLevelName + '</em>' +
					'					</li>' +
					'					<li>' +
					'						信誉等级：' + creditLevelImg +
					'					</li>' +
					'					<li>开店时间：' + da.shop.gmtDatetime + '</li>' +
					'					<li>本月上新：' + monthNew + '</li>' +
					'					<li>本月访问：' + lookTime + '</li>' +
					'				</ul>' +
					'				<div class="detail_right_pinzhi clearfix">' +
					'<span>商家服务：<em>' + da.shop.serviceLevel + '.0</em></span>' +
					'<span>商家品质：<em>' + da.shop.qualityLevel + '.0</em></span>' +
					'<span>物流服务：<em>' + da.shop.carLevel + '.0</em></span>' +
					'				</div>' +
					'				<div class="detail_right_kefu clearfix">' +
					'					<a href="javascript:void(0);" class="public-chat">联系客服</a>' +
					'					<a href="10.1.0dianpu_detail.html?id=' + da.shop.id + '">进入店铺</a>' +
					'					<a href="javascript:void(0);" class="Shoucang"></a>' +
					'				</div>' +
					'				<div class="detail_right_fuwu">' +
					'					<h6>服务宗旨</h6>' +
					'					<div class="clearfix">' +
					'						<span>交易安全</span>' +
					'						<span>质量保证</span>' +
					'						<span>方便省心</span>' +
					'					</div>' +
					'				</div>';

				$('#shopInfo').append(shopInfo);

				//弹窗二维码
				$(function() {
					//弹出
					$('.public-chat').on('click', function() {
						$(".public_simi_bg").fadeIn();
					});
					$(".public_simi_bg").on('click', function() {
						$(".public_simi_bg").fadeOut();
					})
					var focus = da.focusShop == null ? '' : da.focusShop.status;
					//关注店铺
					if(focus == 1) {
						$(".Shoucang").text('取消收藏');
					} else {
						$(".Shoucang").text('收藏店铺');
					}
					//收藏
					$(".Shoucang").click(function() {

						if(userId == null) {
							//显示登录页
							$(".public_simi_bg1").fadeIn();
						} else {
							var id = da.focusShop == null ? '' : da.focusShop.id;

							if($(this).text() == '收藏店铺') {

								if(id == '') {
									//取消关注
									if(!layer.confirm("确认收藏吗?")) {
										return;
									}
									$.ajax({
										url: urlcore + '/api/focusShop/add',
										type: "post",
										contentType: "application/json;charset=utf-8",
										data: JSON.stringify({
											"shopId": da.shop.id,
											"status": 1
										}),
										dataType: "json",
										success: function(data) {
											if(data.success == true) {
												layer.alert("收藏成功");

												//跳转列表页
												window.location.href = "2.2.0goods_detail.html?id=" + da.id;
											} else if(data.code == 'OVERTIME') {
												var thisUrl = window.location.href;
												if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
													top.window.location.href = "1.0.0denglu.html";
												}
											} else {
												layer.alert(data.msg);
											}

										},
										error: function() {
											layer.alert("error");
										}

									});
								} else {
									//取消关注
									if(!layer.confirm("确认收藏吗?")) {
										return;
									}
									$.ajax({
										url: urlcore + '/api/focusShop/update',
										type: "post",
										contentType: "application/json;charset=utf-8",
										data: JSON.stringify({
											"id": id,
											"status": 1
										}),
										dataType: "json",
										success: function(data) {
											if(data.success == true) {
												layer.alert("收藏成功");

												//跳转列表页
												window.location.href = "2.2.0goods_detail.html?id=" + da.id;
											} else if(data.code == 'OVERTIME') {
												var thisUrl = window.location.href;
												if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
													top.window.location.href = "1.0.0denglu.html";
												}
											} else {
												layer.alert(data.msg);
											}

										},
										error: function() {
											layer.alert("error");
										}

									});
								}

							} else {

								//关注
								if(!layer.confirm("确认取消收藏吗?")) {
									return;
								}
								$.ajax({
									url: urlcore + '/api/focusShop/update',
									type: "post",
									contentType: "application/json;charset=utf-8",
									data: JSON.stringify({
										"id": id,
										"status": 2
									}),
									dataType: "json",
									success: function(data) {
										if(data.success == true) {
											layer.alert("取消成功");

											//跳转列表页
											window.location.href = "2.2.0goods_detail.html?id=" + da.id;
										} else if(data.code == 'OVERTIME') {
											var thisUrl = window.location.href;
											if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
												top.window.location.href = "1.0.0denglu.html";
											}
										} else {
											layer.alert(data.msg);
										}

									},
									error: function() {
										layer.alert("error");
									}

								});
							}
						}

					});

				});

				$.each(da.goodsList, function(i, n) {

					var d1 = new Date(n.gmtDatetime);
					var d2 = new Date();
					var min = parseInt(parseInt(d2 - d1) / 1000 / 60); //两个时间相差的分钟数
					var coverUrl = isHasImg(n.coverUrl); //图片处理

					//if(min > 60) {
					//	$('.detail_goods_new_time').hide();
					//}
					if(n.goodsType == 2) {
						var shangxingoodsList =
							'<dl>' +
							'						<a href="2.2.0goods_detail.html?id=' + n.id + '">' +
							'							<dt>' +
							'						<img class="remaiImg" src="' + coverUrl + '" />' +
							'						<!--时间-->' +
							'						<div class="detail_goods_new_time">' + min + '分钟前</div>' +
							'					</dt>' +
							'							<dd>' +
							'								<h6>' + n.goodsTitle + '</h6>' +
							'								<div class="clearfix">' +
							'									<span>&yen;' + n.tradePrice + '-' + n.packPrice + '</span>' +
							'									<em>收藏量：' + n.collectNum + '</em>' +
							'								</div>' +
							'							</dd>' +
							'						</a>' +
							'					</dl>';
						$('#shangxingoodsList').append(shangxingoodsList);
					} else if(n.goodsType == 3) {
						var remaigoodsList =
							'<dl>' +
							'						<a href="2.2.0goods_detail.html?id=' + n.id + '">' +
							'							<dt>' +
							'						<img class="remaiImg" src="' + coverUrl + '" />' +
							'						<!--时间-->' +
							'						<div class="detail_goods_new_time">' + min + '分钟前</div>' +
							'					</dt>' +
							'							<dd>' +
							'								<h6>' + n.goodsTitle + '</h6>' +
							'								<div class="clearfix">' +
							'									<span>&yen;' + n.tradePrice + '-' + n.packPrice + '</span>' +
							'									<em>收藏量：' + n.collectNum + '</em>' +
							'								</div>' +
							'							</dd>' +
							'						</a>' +
							'					</dl>';
						$('#remaigoodsList').append(remaigoodsList);
					}
				});
				//获取商品属性
				$.each(da.myPropertyList, function(i, n) {
					var propertyTypeList =
						'<li>' + n.oneProperty + ' : <span>' + n.twoProperty + '</span></li>';
					$("#propertyLists").append(propertyTypeList);
				});

				//获取商品描述
				$("#goodsSimple").html(""); //商品描述

				var photos1 = '';
				if(da.goodsUrl != null) {
					var photoArr1 = da.goodsUrl.split("***");
					$.each(photoArr1, function(i, val) {
						val = isHasImg(val);
						photos1 += '<img src="' + val + '" alt="Image Name" /><br/><br/>';
					});
				}
				photos1 += '<img src="' + isHasImg(da.coverUrl) + '" alt="Image Name" /><br/><br/>';
				$("#goodsSimple").append(photos1);

			}

			//固定宽高
			$(function() {
				var imgList = document.getElementsByClassName("lunbotuImg");
				var w = 450;
				var h = 450;
				for(var i = 0; i < imgList.length; i++) {
					if(imgList[i].width > w || imgList[i].height > h) {
						imgList[i].width = w;
						imgList[i].heigth = h;
					}
				}

				var imgList0 = document.getElementsByClassName("lunbotuImg2");
				var w0 = 80;
				var h0 = 80;
				for(var i = 0; i < imgList0.length; i++) {
					if(imgList0[i].width > w0 || imgList0[i].height > h0) {
						imgList0[i].width = w0;
						imgList0[i].heigth = h0;
					}
				}

				var imgList1 = document.getElementsByClassName("remaiImg");
				var w1 = 218;
				var h1 = 218;
				for(var i = 0; i < imgList1.length; i++) {
					if(imgList1[i].width > w1 || imgList1[i].height > h1) {
						imgList1[i].width = w1;
						imgList1[i].heigth = h1;
					}
				}
			})
		},
		error: function() {
			layer.alert("error");
		}
	});
}

function getCommentCount(id) {
	$("#selectComment0").html("");
	$("#selectComment1").html("");
	$("#selectComment2").html("");
	$("#selectComment3").html("");
	$("#selectComment4").html("");
	$.ajax({
		url: urlcore + "/api/comment/selectCount?goodsId=" + id,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				var da = data.data;

				if(da.hpSize != null && da.hpSize != '' && da.total != null && da.total != '') {
					//好评率
					var hp = da.hpSize / da.total * 100;

					$("#haoping").text(divsub(hp.toFixed(2)));
				}

				var selectCommentByLevel0 = '全部(' + da.total + ')';
				$("#selectComment0").text(selectCommentByLevel0);

				var selectCommentByLevel1 = '好评(' + da.hpSize + ')';
				$("#selectComment1").text(selectCommentByLevel1);

				var selectCommentByLevel2 = '中评(' + da.zpSize + ')';
				$("#selectComment2").text(selectCommentByLevel2);

				var selectCommentByLevel3 = '差评(' + da.cpSize + ')';
				$("#selectComment3").text(selectCommentByLevel3);

				var selectCommentByLevel4 = '晒图(' + da.stSize + ')';
				$("#selectComment4").text(selectCommentByLevel4);
			}
		},
		error: function() {
			layer.alert("error");
		}
	});
}
//过滤小数以及负数
function myFunction(v) {
	if(!(/(^[1-9]\d*$)/.test(v.value))) {　　　　　　
		v.value = '';　　　　
	}
	//超出剩余库存,清空重新输入
	var leftNum = $(v).parent().find('input[class*=leftNum]').val();
	if(v.value > parseInt(leftNum)) {
		v.value = '';
	}
}

var commentLevel = '';
var isImg = '';
var currentPage = 1;
//列表
function loadMyEssayByComment(id, commentLevel, isImg) {
	$(document).ready(function() {
		init(currentPage);
	});

	function init(pageNo) {
		$("#userCommentList").html("");
		$.ajax({
			url: urlcore + "/api/comment/getCommentByCommentLevel?goodsId=" + id + "&commentLevel=" + commentLevel + "&isImg=" + isImg + "&size=" + 20 + "&current=" + pageNo,
			type: "get",
			dataType: 'json',
			async: false,
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					$.each(data.data.list, function(i, n) {

						var commentImg = '';
						if(n.commentImg.indexOf("***") != -1) {
							var imgArr = n.commentImg.split("***");

							$.each(imgArr, function(i, img) {
								commentImg += '<img src="' + img + '" />';
							});
						}

						var qualityLevel = '';
						if(n.qualityLevel == 1) {
							qualityLevel = '<img src="images/star_select.png" /><em>1.0分</em>';
						} else if(n.qualityLevel == 2) {
							qualityLevel = '<img src="images/star_select.png" /><img src="images/star_select.png" /><em>2.0分</em>';
						} else if(n.qualityLevel == 3) {
							qualityLevel = '<img src="images/star_select.png" /><img src="images/star_select.png" /><img src="images/star_select.png" /><em>3.0分</em>';
						} else if(n.qualityLevel == 4) {
							qualityLevel = '<img src="images/star_select.png" /><img src="images/star_select.png" /><img src="images/star_select.png" /><img src="images/star_select.png" /><em>4.0分</em>';
						} else if(n.qualityLevel == 5) {
							qualityLevel = '<img src="images/star_select.png" /><img src="images/star_select.png" /><img src="images/star_select.png" /><img src="images/star_select.png" /><img src="images/star_select.png" /><em>5.0分</em>';
						}

						var thislist =
							'<dl class="clearfix">' +
							'<dt>' +
							'<img src="' + n.user.headImg + '" />' +
							'</dt>' +
							'<dd class="detail_pingjia">' +
							'<h6>' + n.user.userName + '</h6>' +
							'<span>' + n.gmtDatetime + '</span>' +
							'<p>' + n.commentContent + '</p>' +
							'<div class="dianpu_pingjia_xinxi_star clearfix">' + qualityLevel + '</div>' +
							'<div class="dianpu_pingjia_xinxi_img">' + commentImg + '</div>' +
							'</dd>' +
							'</dl>';
						$('#userCommentList').append(thislist);
					});

					$("#pager").pager({
						pagenumber: pageNo,
						pagecount: data.data.pages,
						totalcount: data.data.total,
						buttonClickCallback: PageClick
					});

				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}

				} else {
					if(data.msg != '空数据') {
						layer.alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}

			},
			error: function() {
				layer.alert("error");
			}
		});
	}
	PageClick = function(pageclickednumber) {
		init(pageclickednumber);
	}
}

function selectComment(commentLevel, isImg) {
	loadMyEssayByComment(id, commentLevel, isImg);
}

function getLogin1() {
	var phone = $('#phone').val().trim();
	if(phone == '') {
		layer.alert("请输入手机号码！");
		return false;
	}
	var password = $('#password').val().trim();
	if(password == '') {
		layer.alert("请输入登录密码！");
		return false;
	}
	$.ajax({
		url: urlcore + "/api/user/loginByPhone",
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			"phone": phone,
			"password": password
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				if(layer.confirm("登录成功！")) {

					var da = data.data;
					//var url="index.html?userName="+da.userName;
					//window.location.href = encodeURI(url);

					if(window.sessionStorage) {
						//登录名
						sessionStorage.setItem("userName", da.userName);
						//登录类型
						sessionStorage.setItem("userType", da.userType);
						sessionStorage.setItem("userId", da.id);
						//设置cookie
						var domain_url = urlcore.split('://')[1];
						if(domain_url.indexOf(':') > -1) {
							domain_url = domain_url.split(':')[0];
						} else {
							domain_url = domain_url.split('/')[0];
						}
						document.cookie = "JSESSIONID=" + data.data.token + ";path=/;domain=" + domain_url;

						//	sessionStorage.setItem("userId",da.id);
						window.location.href = "2.2.0goods_detail.html?id=" + id;
					} else {
						layer.alert("浏览暂不支持sessionStorage");
					}

					//或者 if(typeof window.localStorage == 'undefined'){ 	alert("浏览暂不支持localStorage") }
					//刷新
					//location.reload();

				} else {
					//跳转列表页
					window.location.href = "1.0.0denglu.html";
				}
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
					top.window.location.href = "1.0.0denglu.html";
				}
			} else {
				layer.alert(data.msg);
			}
		},
		error: function() {
			layer.alert("error");
		}

	});
}

//倒计时
$(function() {
	countDown("2017/12/30 00:00:00", null, "#demo02 .hour", "#demo02 .minute", "#demo02 .second");
});

function countDown(time, day_elem, hour_elem, minute_elem, second_elem) {
	//if(typeof end_time == "string")
	var end_time = new Date(time).getTime(), //月份是实际月份-1
		//current_time = new Date().getTime(),
		sys_second = (end_time - new Date().getTime()) / 1000;
	var timer = setInterval(function() {
		if(sys_second > 0) {
			sys_second -= 1;
			var day = Math.floor((sys_second / 3600) / 24);
			var hour = Math.floor((sys_second / 3600) % 24);
			var minute = Math.floor((sys_second / 60) % 60);
			var second = Math.floor(sys_second % 60);
			day_elem && $(day_elem).text(day); //计算天
			$(hour_elem).text(hour < 10 ? "0" + hour : hour); //计算小时
			$(minute_elem).text(minute < 10 ? "0" + minute : minute); //计算分
			$(second_elem).text(second < 10 ? "0" + second : second); // 计算秒
		} else {
			clearInterval(timer);
		}
	}, 1000);
}